#define _CRT_SECURE_NO_WARNINGS

#include "Sort.h"

void IsSorted(DataType* arr, int n)
{
	int i = 0;
	for (i = 0; i < n - 1; i++)
	{
		if (arr[i] > arr[i + 1])
		{
			printf("Not sorted.\n");
			return;
		}
	}
	printf("Sorted.\n\n");
}

void TimeTest(void (*Sort)(DataType* , int), int* arr, int n)
{
	int t1 = 0, t2 = 0;
	t1 = (int)clock();
	Sort(arr, n);
	t2 = (int)clock();
	printf("Time:%dms\n", t2 - t1);
}

void InsertSort(DataType* arr, int n)
{
	for (int i = 1; i < n; i++)
	{
		DataType Temp = arr[i];
		int j = i - 1;

		for (; j >= 0 && arr[j] > Temp; j--)
		{
			arr[j + 1] = arr[j];
		}
		arr[j + 1] = Temp;
	}
}

void ShellSort(DataType* arr, int n)
{
	int gap = n / 2;
	int i = 0, j = 0;
	DataType temp = 0;
	for (; gap > 0; gap /= 2)
	{
		for (i = gap; i < n; i++)
		{
			j = i - gap;
			temp = arr[i];
			for (; j >= 0 && arr[j] > temp; j -= gap)
			{
				arr[j + gap] = arr[j];
			}
			arr[j + gap] = temp;
		}
	}
}
